*APSR replication material
*Title: Triggering Ideological Thinking: How Elections Foster Coherence of Welfare State Attitudes
*Author: Tobias Heide-Jørgensen

*PURPOSE: Reproducing results in terms of tables and figures from the article.

*REQUIRED PACKAGES: estout mylabels


********************							
*** Main results ***							
********************							

*Reading data
use "replication_data.dta", clear

*Dropping respondents whose municipality id is based on zip codes in which 80% or less live in the municipality, as described in the article					
drop if prop_zipmun<=0.8

*Figure 1											
qui: reg redis i.ideo_group i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year,cluster(mun_id)							
eststo redis_ideo: margins, at(ideo_group=(1 2 3)) post							

qui: reg taxwel i.ideo_group i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year,cluster(mun_id)							
eststo taxwel_ideo: margins, at(ideo_group=(1 2 3)) post
					
mylabels 0.4 (0.1) 0.8, format(%04.3f) clean local(wel_att) 	
						
coefplot redis_ideo,vertical coeflabels(1._at="Leftists" 2._at="Centrists" 3._at="Rightists") byopts(yrescale) ylabel(`wel_att', grid angle(h) labsize(small)) xlabel(,labsize(small)) levels(95 90) nokey mcolor(gs0) ciopts(color(gs12 gs8)) scheme(s1mono) graphregion(color(white)) plotregion(lcolor(white)) title(Support for redistribution) saving(redis_ideo, replace) 
								
coefplot taxwel_ideo,vertical coeflabels(1._at="Leftists" 2._at="Centrists" 3._at="Rightists") byopts(yrescale) ylabel(`wel_att', grid angle(h) labsize(small)) xlabel(,labsize(small)) levels(95 90) plotregion(lcolor(white)) nokey mcolor(gs0) ciopts(color(gs12 gs8)) scheme(s1mono) graphregion(color(white)) title(Support for welfare spending) saving(taxwel_ideo, replace) 
													
gr combine redis_ideo.gph taxwel_ideo.gph, graphregion(color(white)) ycommon

reg redis i.ideo_group i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year,cluster(mun_id)
reg redis ib(2).ideo_group i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year,cluster(mun_id) //Group means are significantly different
										
*Figure 2
foreach num of numlist 1/3 {
qui: reg redis taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year if ideo_group==`num',cluster(mun_id)							
estimate store taxredis_`num'
}
															
mylabels 0.02 (0.02) 0.12, format(%04.3f) clean local(taxwel_ideo)
							
coefplot taxredis_1, bylabel("Leftists") || taxredis_2, bylabel("Centrists") || taxredis_3, bylabel("Rightists") keep(taxwel) vertical bycoefs byopts(yrescale) ylabel(`taxwel_ideo',grid angle(h) labsize(small)) xlabel(,labsize(small)) levels(95 90) nokey mcolor(gs0) plotregion(lcolor(white)) ciopts(color(gs12 gs8)) scheme(s1mono) graphregion(color(white)) ytitle(Welfare attitude consistency)							

reg redis c.taxwel##ideo_group i.male##ideo_group c.age##c.age##ideo_group i.inc##ideo_group i.sec_edu##ideo_group i.hig_edu##ideo_group i.occu##ideo_group i.year##ideo_group,cluster(mun_id)
reg redis c.taxwel##ib(3).ideo_group i.male##ib(3).ideo_group c.age##c.age##ib(3).ideo_group i.inc##ib(3).ideo_group i.sec_edu##ib(3).ideo_group i.hig_edu##ib(3).ideo_group i.occu##ib(3).ideo_group i.year##ib(3).ideo_group,cluster(mun_id) //Differences in consistency.

*Table 1
foreach num of numlist 15 10 5 {
qui eststo lfull: reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if ideo_group==1, cluster(mun_id)							
estadd local bandwidth "Full sample", replace							
							
qui eststo l`num': reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if inrange(right_run,-`num',`num') & ideo_group==1, cluster(mun_id)					
estadd local bandwidth "+/- `num' pp.", replace							
}
																		
esttab lfull l15 l10 l5, title(Welfare Attitude Crystallization among Leftists) b(2) se starlevels(* 0.1 ** 0.05 *** 0.01) stats(bandwidth N, fmt(%9.0fc) label("Bandwidth" "Observations")) indicate("Covariates = *.inc" "Running variable = right_run") keep(taxwel 1.right_above 1.right_above#c.taxwel _cons) label order(taxwel 1.right_above 1.right_above#c.taxwel _cons)

reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if inrange(right_run,-10,10) & ideo_group==1, cluster(mun_id)
sum taxwel if e(sample)==1
di .0510001*.3590253 //Consistency among untreated individuals expressed in terms of standard deviations
						
*Table 2
foreach num of numlist 15 10 5 {
qui eststo rfull: reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if ideo_group==3, cluster(mun_id)							
estadd local bandwidth "Full sample", replace							
							
qui eststo r`num': reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if inrange(left_run,-`num',`num') & ideo_group==3, cluster(mun_id)							
estadd local bandwidth "+/- `num' pp.", replace							
}
										
esttab rfull r15 r10 r5, title(Welfare Attitude Crystallization among Rightists) b(2) se starlevels(* 0.1 ** 0.05 *** 0.01) stats(bandwidth N, fmt(%9.0fc) label("Bandwidth" "Observations")) indicate("Covariates = *.inc" "Running variable = left_run") keep(taxwel 1.left_above 1.left_above#c.taxwel _cons) label order(taxwel 1.left_above 1.left_above#c.taxwel _cons)							

reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if inrange(left_run,-10,10) & ideo_group==3, cluster(mun_id)							
sum taxwel if e(sample)==1
di .0864608*.4569497 //Consistency among untreated individuals expressed in terms of standard deviations
						
*Figure 3
foreach num of numlist 15 10 5/2 {
qui: reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if ideo_group==1, cluster(mun_id)							
estimate store left_full

qui: reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if inrange(right_run,-`num',`num') & ideo_group==1, cluster(mun_id)							
estimate store left_`num' 

qui: reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if inrange(right_run,-1.7,1.7) & ideo_group==1, cluster(mun_id)							
estimate store left_17

qui: reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if ideo_group==3, cluster(mun_id)							
estimate store right_full

qui: reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if inrange(left_run,-`num' ,`num' ) & ideo_group==3, cluster(mun_id)							
estimate store right_`num' 

qui: reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if inrange(left_run,-1.7 ,1.7 ) & ideo_group==3, cluster(mun_id)							
estimate store right_17
}
														
mylabels -0.4 (0.1) 0.4, format(%04.3f) clean local(label)
 							
coefplot left_full, bylabel("Full" "sample") || left_15, bylabel("+/-" "15 pp.") || left_10, bylabel("+/-" "10 pp.") || left_5, bylabel("+/-" "5 pp.") || left_4, bylabel("+/-" "4 pp.") || left_3, bylabel("+/-" "3 pp.") || left_2, bylabel("+/-" "2 pp.") || left_17, bylabel("+/-" "1.7 pp.") keep(1.right_above#c.taxwel) vertical yline(0, lpattern(dash)) bycoefs byopts(yrescale) ylabel(`label',grid angle(h) labsize(small)) xlabel(,labsize(small)) levels(95 90) nokey mcolor(gs0) ciopts(color(gs12 gs8)) scheme(s1mono) graphregion(color(white)) plotregion(lcolor(white)) ytitle(Effect of right-wing majority on consistency, size(small)) title("Leftists") saving(_left, replace)
													
coefplot right_full, bylabel("Full" "sample") || right_15, bylabel("+/-" "15 pp.") || right_10, bylabel("+/-" "10 pp.") || right_5, bylabel("+/-" "5 pp.") || right_4, bylabel("+/-" "4 pp.") || right_3, bylabel("+/-" "3 pp.") || right_2, bylabel("+/-" "2 pp.") || right_17, bylabel("+/-" "1.7 pp.") keep(1.left_above#c.taxwel)  vertical nolabels yline(0, lpattern(dash)) bycoefs byopts(yrescale) ylabel(`label',grid angle(h) labsize(small)) xlabel(,labsize(small)) levels(95 90) nokey mcolor(gs0) ciopts(color(gs12 gs8)) scheme(s1mono) graphregion(color(white)) plotregion(lcolor(white)) ytitle(Effect of right-wing majority on consistency, size(small)) title("Rightists") saving(_right, replace)							
							
gr combine _left.gph _right.gph, graphregion(color(white)) ycommon							

*Table 3
eststo eduleft1: reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if inrange(right_run,-10,10) & ideo_group==1 & hig_edu!=99, cluster(mun_id)
estadd local bandwidth "+/- 10 pp.", replace							

di .0890083/.0471359*100 //Leftists: Percentage difference in consistency comparing treated and untreated individuals

eststo eduleft2: reg redis hig_edu##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.occu i.year if e(sample)==1, cluster(mun_id) 							
estadd local bandwidth "+/- 10 pp.", replace							

di .063965/.0641718*100 //Leftists: Percentage difference in consistency comparing those with and those without a higher education
							
eststo eduright1: reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if inrange(left_run,-10,10) & ideo_group==3 & hig_edu!=99, cluster(mun_id)					
estadd local bandwidth "+/- 10 pp.", replace							

di .036593/.0874316*100 //Rightists: Percentage difference in consistency comparing treated and untreated individuals
							
eststo eduright2: reg redis hig_edu##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.occu i.year if e(sample)==1,cluster(mun_id) 
estadd local bandwidth "+/- 10 pp.", replace							

di .0475494/.0891379*100 //Rightists: Percentage difference in consistency comparing those with and those without a higher education
						
esttab eduleft1 eduleft2 eduright1 eduright2, title(Comparing with Educational Effect) b(2) se starlevels(* 0.1 ** 0.05 *** 0.01) stats(bandwidth N, fmt(%9.0fc) label("Bandwidth" "Observations")) indicate("Covariates = *.inc" "Running variable = left_run right_run") keep(taxwel 1.right_above 1.left_above 1.hig_edu 1.right_above#c.taxwel 1.left_above#c.taxwel 1.hig_edu#c.taxwel _cons) label order(taxwel 1.right_above 1.left_above 1.hig_edu 1.right_above#c.taxwel 1.left_above#c.taxwel 1.hig_edu#c.taxwel _cons)
	
*Table 4
qui eststo coce1: reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if inrange(right_run,-10,10) & ideo_group==3, cluster(mun_id)							
estadd local bandwidth "+/- 10 pp.", replace							
							
qui eststo coce2: reg redis right_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year right_run c.right_run#c.right_run right_above#c.right_run right_above#c.right_run#c.right_run if inrange(right_run,-10,10) & ideo_group==2, cluster(mun_id)		
estadd local bandwidth "+/- 10 pp.", replace							
		
qui eststo coce3: reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if inrange(left_run,-10,10) & ideo_group==1, cluster(mun_id)	
estadd local bandwidth "+/- 10 pp.", replace							
							
qui eststo coce4: eststo desc_stat: reg redis left_above##c.taxwel i.male c.age##c.age i.inc i.sec_edu i.hig_edu i.occu i.year left_run c.left_run#c.left_run left_above#c.left_run left_above#c.left_run#c.left_run if inrange(left_run,-10,10) & ideo_group==2, cluster(mun_id)	
estadd local bandwidth "+/- 10 pp.", replace							

esttab coce1 coce2 coce3 coce4, title(Welfare Attitude Crystallization: Consonant Majorities and Centrists) b(2) se starlevels(* 0.1 ** 0.05 *** 0.01) stats(bandwidth N, fmt(%9.0fc) label("Bandwidth" "Observations")) indicate("Covariates = *.inc" "Year effects = *.year" "Running variable = left_run right_run") keep(taxwel 1.right_above 1.left_above 1.right_above#c.taxwel 1.left_above#c.taxwel _cons) label order(taxwel 1.right_above 1.left_above 1.right_above#c.taxwel 1.left_above#c.taxwel _cons)